const mongoose = require("mongoose");
const { dbUri } = require('../config/config.default')

// 连接数据库
mongoose.connect(dbUri, {
  dbName: 'realworld',
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const db = mongoose.connection;
db.on('error', err => {
  console.log('数据库连接失败', err)
});
db.once('open', function() {
  console.log('数据库连接成功')
});

module.exports = {
  User: mongoose.model('User', require('./user')),
  Article: mongoose.model('Article', require('./article'))
}